05. Asynchronous vs Synchronous Requests
Asynchronous vs Synchronous Requests
Question:
Before we start diving into asynchronous requests, let's consider some real-world scenarios that might require one.
Remember, an asynchronous request can be fired off at any time (before or after a page has loaded) and the response to an asynchronous request often includes HTML that can be dynamically inserted into a page.
Facebook uses a lot of asynchronous requests so that the page almost never needs to refresh for users to see new content.
Take a moment to consider when Facebook might take advantage of asynchronous requests to load new content without refreshing the page. Think about user actions that might lead to asynchronous requests. For instance, when a user scrolls down in a business' page (like Udacity's Facebook page), new stories get inserted into the page which never needs to refresh to show new content (more on this specific example in a moment). This is an example of an asynchronous request.
Click "Skip to Quiz" when you're ready to identify some more examples!
Start Quiz:
Solution:
Starting from the top, Scrolling down in the Newsfeed automatically loads new stories. The page never refreshes, which means that Facebook is using asynchronous requests to pull in new Newsfeed content. So, this is an example of asynchronous request.
Next up, we've got Loading the homepage when not signed in. The log in screen is essentially a static page and does not require asynchronous requests after the page loads.
Then we've got Posting a message on a friend's Timeline. The page doesn't need to refresh after you hit "Post;" it simply inserts your post into the page. This must be an asynchronous request.
Lastly, we have Clicking through a friend's pictures. Pictures will load in the page indefinitely (so long as there are more pictures in the album) without requiring a full page refresh. New images simply appear. This is also an example of an asynchronous request.
INSTRUCTOR NOTE:
Here's some help:
- Scrolling down in the Newsfeed: when you scroll down, new stories are automatically loaded.
- Loading the homepage when not signed in: open Facebook in Incognito Mode to see what I mean.
- Posting a message on a friend's Timeline: Does the page reload when you post? How does the page change after you hit "Post"?
- Clicking through a friend's pictures: Does the page ever need to refresh when you are scrolling through a friend's pictures?